from django.db import models

# Create your models here.


class User(models.Model):
    id = models.AutoField(primary_key=True)
    job_number = models.CharField(max_length=8, verbose_name='工号')
    password = models.CharField(max_length=32, verbose_name='密码')
    username = models.CharField(max_length=16, verbose_name='姓名')
    gender = models.IntegerField(verbose_name='性别（1：男 2：女 3：未知）')
    post_id = models.ForeignKey('Post', on_delete=models.CASCADE)
    source = models.CharField(max_length=16, verbose_name='来源')
    manage_area = models.CharField(max_length=32, verbose_name='管理区域')
    phone = models.CharField(max_length=16, verbose_name='联系方式')
    id_num = models.CharField(max_length=18, verbose_name='身份证号')
    office_date = models.DateField(auto_now=False, auto_now_add=False, verbose_name='任职日期')
    off_office_date = models.DateField(auto_now=False, auto_now_add=False, verbose_name='离职日期')
    status = models.IntegerField(verbose_name='启用状态（1：启用 2：未启用）')
    is_delete = models.IntegerField(verbose_name='删除状态（1:正常 2:不正常）', default=1)


class Post(models.Model):
    post_name = models.CharField(max_length=16, verbose_name='岗位名称')
    description = models.CharField(max_length=2560, verbose_name='岗位描述')
    status = models.IntegerField(verbose_name='状态（1:正常 2:不正常）', default=1)
    is_delete = models.IntegerField(verbose_name='删除状态（1:正常 2:不正常）', default=1)


class Author(models.Model):
    author_name = models.CharField(max_length=16, verbose_name='权限名称')
    author_name_en = models.CharField(max_length=32, verbose_name='权限(英文)名称')
    url = models.CharField(max_length=16, verbose_name='路由地址')
    pid = models.IntegerField(verbose_name='父级节点ID', default=0)
    is_delete = models.IntegerField(verbose_name='删除状态（1:正常 2:不正常）', default=1)
    post_id = models.ManyToManyField(Post)


class Floor(models.Model):
    floor_name = models.CharField(max_length=16, verbose_name='楼层名称')
    description = models.CharField(max_length=2560, verbose_name='楼层说明')
    is_delete = models.IntegerField(verbose_name='删除状态（1:正常 2:不正常）', default=1)


class DormSpecs(models.Model):
    scale = models.IntegerField(verbose_name='宿舍规格（2：双人间，4：四人间：6：六人间，8：八人间，10：十人间）',  default=8)
    num = models.IntegerField(verbose_name='人数', default=0)
    description = models.CharField(max_length=2560, verbose_name='说明')
    is_delete = models.IntegerField(verbose_name='删除状态（1:正常 2:不正常）', default=1)


class Equipment(models.Model):
    equipment_name = models.CharField(max_length=16, verbose_name='家电名称')
    description = models.CharField(max_length=2560, verbose_name='说明')
    is_delete = models.IntegerField(verbose_name='删除状态（1:正常 2:不正常）')


class Dorm(models.Model):
    floor = models.ForeignKey('Floor', on_delete=models.CASCADE)
    spec = models.ForeignKey('DormSpecs', on_delete=models.CASCADE)
    dorm_name = models.CharField(max_length=16, verbose_name='房间号')
    equipment_id = models.ManyToManyField(
        Equipment,
        through='DormEquipRela',
        through_fields=('dorm', 'equip')
    )


class DormEquipRela(models.Model):
    dorm = models.ForeignKey(Dorm, on_delete=models.CASCADE)
    equip = models.ForeignKey(Equipment, on_delete=models.CASCADE)
    num = models.IntegerField(verbose_name='家电数量')
    des = models.CharField(max_length=256, verbose_name='描述1')


class Students(models.Model):
    id = models.AutoField(primary_key=True)
    stu_number = models.CharField(max_length=8, verbose_name='学号')
    username = models.CharField(max_length=16, verbose_name='姓名')
    grade = models.CharField(max_length=16, verbose_name='年级（22届）')
    class_name = models.IntegerField(verbose_name='专业名称（1.24电商综合一班；2.22大数据软件开发；3.23网络技术；4.21幼师）')
    gender = models.IntegerField(verbose_name='性别（1：男 2：女 3：未知）')
    stu_phone = models.CharField(max_length=16, verbose_name='学生手机号')
    par_phone = models.CharField(max_length=16, verbose_name='家长手机号')
    dorm_id = models.ForeignKey('Dorm', on_delete=models.CASCADE)
    floor_id = models.ForeignKey('Floor', on_delete=models.CASCADE)
    course_id = models.ForeignKey('CourseMaster', on_delete=models.CASCADE)
    hobby = models.CharField(max_length=32, verbose_name='爱好（存储时，用json字符串存）')
    is_distribution = models.IntegerField(verbose_name='是否分配（1：分配；2：未分配）')
    status = models.IntegerField(verbose_name='启用状态（1：启用 2：未启用）')
    is_delete = models.IntegerField(verbose_name='删除状态（1:正常 2:不正常）', default=1)


class SchoolLocation(models.Model):
    lat = models.CharField(max_length=16, verbose_name='纬度')
    long = models.CharField(max_length=16, verbose_name='经度')
    is_delete = models.IntegerField(verbose_name='删除状态（1:正常 2:不正常）', default=1)


class CourseMaster(models.Model):
    year = models.CharField(max_length=32, verbose_name='学年')
    semester = models.IntegerField(verbose_name='学期（1：第一学期 2：第二学期）')
    name = models.CharField(max_length=64, verbose_name='课程表名称')
    major_id = models.CharField(max_length=64, verbose_name='专业的id(1.24电商综合一班；2.22大数据软件开发；3.23网络技术；4.21幼师)')
    is_delete = models.IntegerField(verbose_name='删除状态（1:正常 2:不正常）', default=1)


class CourseSlave(models.Model):
    name = models.CharField(max_length=64, verbose_name='星期')
    first_class = models.CharField(max_length=64, verbose_name='第一节课')
    second_class = models.CharField(max_length=64, verbose_name='第二节课')
    third_class = models.CharField(max_length=64, verbose_name='第三节课')
    fourth_class = models.CharField(max_length=64, verbose_name='第四节课')
    fifth_class = models.CharField(max_length=64, verbose_name='第五节课')
    sixth_class = models.CharField(max_length=64, verbose_name='第六节课')
    master_id = models.CharField(max_length=64, verbose_name='存储主表的id')
    is_delete = models.IntegerField(verbose_name='删除状态（1:正常 2:不正常）', default=1)

